home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Hardware / Mac OS USB DDK v1.3f3 / Examples / PrinterClassDriver / DRVRGlue.a < prev    next >
Encoding:
Text File  |  1999-08-20  |  4.3 KB  |  147 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        DRVRGlue.a
  3. ;
  4. ;    Contains:    DRVR interface
  5. ;    Version:    xxx put version here xxx
  6. ;
  7.  
  8. ;
  9. ;    Copyright:     1998 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    File Ownership:
  12. ;
  13. ;        DRI:                xxx put dri here xxx
  14. ;
  15. ;        Other Contact:        xxx put other contact here xxx
  16. ;
  17. ;        Technology:            xxx put technology here xxx
  18. ;
  19. ;    Writers:
  20. ;
  21. ;        (DF)    David Ferguson
  22. ;
  23. ;    Change History (most recent first):
  24. ;
  25. ;      <USB5>      6/7/99    DF        convert interface to C, return proper results for immediate,
  26. ;                                    sync & async cases.
  27. ;        27 Jul 98    oja        VMImmuneMask not set so that we HoldMemory on io buffers, param blocks
  28. ;        24 Apr 98    oja        DrvrDone takes an error, passes on to JIODone
  29. ;        26 Mar 98    oja        changed driver name to ".USB--Print___"
  30. ;        28 Feb 98    oja        loosely based on Apple's StyleWriter DRVR
  31. ;
  32. ;    To Do:
  33. ;
  34.  
  35.         
  36.     BLANKS    ON
  37.     STRING    ASIS
  38.         
  39.     INCLUDE        'LowMem.a'
  40.     INCLUDE        'Devices.a'
  41. ;
  42. ;    for an explanation of VMimmune and gestalt see AsyncDriverSample 1.0b4
  43. ;
  44. dVMImmuneMask                EQU    $0001
  45. dDriverGestaltEnableMask    EQU    $0004    ; See DriverGestalt.h
  46.  
  47. drvrFlags        EQU    dReadEnableMask +  dWritEnableMask + dCtlEnableMask +  dStatEnableMask
  48. drvrSystemFlags    EQU dNeedLockMask
  49.  
  50. DRVREntry        MAIN    EXPORT
  51.  
  52.                 IMPORT    DRVROpen, DRVRPrime, DRVRControl, DRVRStatus, DRVRClose
  53.  
  54. Header
  55.         dc.w    drvrFlags + drvrSystemFlags
  56.         DC.W    0        ; no run time
  57.         DC.W    0        ; no events
  58.         DC.W    0        ; no menu
  59.  
  60. ; Entry point offset table to the procs: Open, Prime, Control, Status, Close
  61.         DC.W    MyOpen        - DRVREntry  ; open routine
  62.         DC.W    MyPrime        - DRVREntry  ; prime
  63.         DC.W    MyControl    - DRVREntry  ; control
  64.         DC.W    MyStatus    - DRVREntry  ; status
  65.         DC.W    MyClose        - DRVREntry  ; close
  66.  
  67. ; Title
  68. ;        include three pad bytes so we can re-number the driver
  69.         DC.B    14                    ;Length byte
  70.         DC.B    '.USB--Print---'    ;Pad to odd # of chars, so 1st routine
  71.                                     ;  will be word-aligned.
  72.  
  73. ; Push the address of the routine we wish to call and jump to the glue
  74. ; which sets up the parameters and calls the actual driver implementation
  75. MyOpen        PEA        DRVROpen
  76.             bra.s    MyImmGlue
  77. MyPrime        PEA        DRVRPrime
  78.             bra.s    MyIOGlue
  79. MyControl    PEA        DRVRControl
  80.             bra.s    MyCtlGlue
  81. MyStatus    PEA        DRVRStatus
  82.             bra.s    MyIOGlue
  83. MyClose        PEA        DRVRClose
  84.  
  85. ;
  86. ; This glue code is used for Open/Close  - functions that only return immediate results
  87. ;
  88.  
  89. MyImmGlue
  90.             MOVEM.L    A0-A1,-(A7)                ; save params to the routine
  91.             MOVE.L    A1,-(A7)                ; pass the device control entry
  92.             MOVE.L    A0,-(A7)                ; pass the parameter block
  93.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  94.             JSR        (A0)                    ; do it
  95.             ADDQ    #8,SP                    ; clean up stack
  96.             MOVEM.L    (A7)+,A0-A1                ; restore device parameters
  97.             ADDQ    #4,SP                    ; removed function address 
  98.             BRA.S    ImmedRTS                ; just return
  99.  
  100. MyCtlGlue
  101.             MOVEM.L    A0/A1,-(A7)                ; save params to the routine
  102.             MOVE.L    A1,-(A7)                ; pass the device control entry
  103.             MOVE.L    A0,-(A7)                ; pass the parameter block 
  104.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  105.             JSR        (A0)                    ; do it
  106.             ADDQ    #8,SP                    ; clean up stack
  107.             MOVEM.L    (A7)+,A0/A1                ; restore device parameters
  108.             ADDQ    #4,SP                    ; removed function address 
  109.             CMPI.W    #killCode,CntrlParam.csCode(A0)
  110.             BNE.B    IOReturn                ; killIO always returns immediately
  111.             BRA.S    ImmedRTS
  112.  
  113. MyIOGlue
  114.             MOVEM.L    A0/A1,-(A7)                ; save params to the routine
  115.             MOVE.L    A1,-(A7)                ; pass the device control entry
  116.             MOVE.L    A0,-(A7)                ; pass the parameter block
  117.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  118.             JSR        (A0)                    ; do it
  119.             ADDQ    #8,SP                    ; clean up stack
  120.             MOVEM.L    (A7)+,A0/A1                ; restore device parameters
  121.             ADDQ    #4,SP                    ; removed function address 
  122.             
  123. IOReturn    
  124.             MOVE.W    IOParam.ioTrap(A0), D1
  125.             BTST    #noQueueBit,D1            ; test for an async call
  126.             BEQ.S    Queued                    ; if not async, we're done
  127.             
  128.             TST.W    D0                        ; test async return result
  129.             BLE.B    ImmedRTS                ; if error or noErr we should return immediately
  130.             CLR.W    D0                        ; in progress gets converted to noErr
  131. ImmedRTS            
  132.             MOVE.W    D0,IOParam.ioResult(a0)    ; return the immediate result
  133.             RTS
  134.  
  135. Queued        
  136.             TST.W    D0                        ; test async return result
  137.             BLE.B    IODone                    ; if io is complete then we should return through the jIODone vector
  138.             CLR.W    D0                        ; in progress gets converted to noErr
  139.             RTS
  140. IODone            
  141.             SUBQ.W    #4,A7                    ; else get the JIODone vector
  142.             _LMGetJIODone                    ; so we can jump to it.
  143.             RTS
  144.             
  145.             ENDPROC
  146.     END
  147.